package com.chixing.ih.module.admin.mapper.Provider;

import com.chixing.ih.util.EmptyUtil;
import org.apache.ibatis.jdbc.SQL;

public class AdminUserMapperProvider {

    //1-管理员;2-VIP用户;3-普通用户
    public String getOrdinaryUser(String keyword) {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_user");
            if(!EmptyUtil.isEmpty(keyword)){
                WHERE("nick_name LIKE CONCAT('%',#{keyword},'%')");
            }
            AND();
            WHERE("role_id = 3 AND is_deleted = 0");
            ORDER_BY("update_time DESC");
        }}.toString();
    }



    public String getVipUser(String keyword) {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_user");
            if(!EmptyUtil.isEmpty(keyword)){
                WHERE("nick_name LIKE CONCAT('%',#{keyword},'%')");
            }
            AND();
            WHERE("role_id = 2 AND is_deleted = 0");
            ORDER_BY("update_time DESC");
        }}.toString();
    }

    public String getBlacklistedUser(String keyword) {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_user");
            if(!EmptyUtil.isEmpty(keyword)){
                WHERE("nick_name LIKE CONCAT('%',#{keyword},'%')");
            }
            AND();
            WHERE("is_deleted = 1");
            ORDER_BY("update_time DESC");
        }}.toString();
    }

    //0-未设置;1-已设置
    public String addToBlacklist(Integer id) {
        return new SQL() {{
            UPDATE("tbl_user");
            SET("is_deleted = 1");
            WHERE("user_id = #{id}");
        }}.toString();
    }

    public String removeToBlacklist(Integer id) {
        return new SQL() {{
            UPDATE("tbl_user");
            SET("is_deleted = 0");
            WHERE("user_id = #{id}");
        }}.toString();
    }

    public String getUserMail(Integer id) {
        return new SQL() {{
            SELECT("user_email");
            FROM("tbl_user");
            WHERE("user_id = #{id}");
        }}.toString();
    }

}
